//
//  TPPicker_general.m
//  TPPickerDemo
//
//  Created by 谭鹏 on 2017/8/4.
//  Copyright © 2017年 谭鹏. All rights reserved.
//

#import "TPPicker_general.h"



@interface TPPicker_general()<UITableViewDataSource,UITableViewDelegate>

@end


@implementation TPPicker_general


-(void)setTableViews:(NSArray<UITableView *> *)tableViews height:(CGFloat)height{
    for (UITableView * tableView in self.contentContainer.subviews) {
        [tableView removeFromSuperview];
    }
    _tableViews = tableViews;
    for (UITableView * tableView in tableViews) {
        if ([self.dataSource respondsToSelector:@selector(picker:widthFortableView:)]) {
            [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo([self.dataSource picker:self widthFortableView:tableView]);
            }];
        }
        
        [self.contentContainer addSubview:tableView];
        tableView.dataSource = self;
        tableView.delegate = self;
    }
    [self.contentContainer mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(height);
    }];
    if (![self.dataSource respondsToSelector:@selector(picker:widthFortableView:)]) {
        [self.contentContainer setGridConstraintsWithChildViews:nil colunm:tableViews.count childViewHeight:0 childViewWidth:0 rowSpace:0 colunmSpace:5 edgeInsets:UIEdgeInsetsZero];
    }else{
        [self.contentContainer setGridConstraintsWithChildViews:nil colunm:tableViews.count childViewHeight:0 childViewWidth:-2 rowSpace:0 colunmSpace:5 edgeInsets:UIEdgeInsetsZero];
    }
    
    
    
}

- (void)reloadDataSource{
    for (UITableView * tableView in self.contentContainer.subviews) {
        [tableView reloadData];
    }
}

#pragma mark - delegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSInteger number = [self.dataSource picker:self tableView:tableView numberOfRowsInSection:section];
    return number;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self.dataSource picker:self  tableView:tableView cellForRowAtIndexPath:indexPath];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
@end
